package com.zzk.lanouhn.myapplication1.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.adapters.InvestViewAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lanouhn on 16/8/23.
 */
public class InvestFragment extends Fragment{
    private ViewPager viewPager;
    private TabLayout tabLayout;



    private List<String> tabName;
    private List<Fragment> fragments;
    private InvestViewAdapter adapter;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_invest,null);
        viewPager= (ViewPager) view.findViewById(R.id.viewPager_invest);
        tabLayout= (TabLayout) view.findViewById(R.id.talayout_invest);
        initData();
        return view;
    }

    private void initData() {
        tabName=new ArrayList<>();
        tabName.add("最新");
        tabName.add("新闻");
        tabName.add("赛事");
        tabName.add("娱乐");

        fragments=new ArrayList<>();
        InvestOneFragment iof=new InvestOneFragment();
        fragments.add(iof);
        InvestTwoFragment itf=new InvestTwoFragment();
        fragments.add(itf);
        InvestThreeFragment itff=new InvestThreeFragment();
        fragments.add(itff);
        InvestFourFragment iff=new InvestFourFragment();
        fragments.add(iff);

        //实例化适配器
        adapter=new InvestViewAdapter(getFragmentManager(),tabName,fragments);
        //设置适配器
        viewPager.setAdapter(adapter);
        //tablayout绑定viewpoint
        tabLayout.setupWithViewPager(viewPager);
    }
}
